import fieldRegistry from "@/components/form/FieldRegistry";

export default {
    render(config, context) {
        let fieldConfig = context.formDefinition.fields.find(f => f.id === config.id);
        if (!fieldConfig || !fieldRegistry[fieldConfig.comp]) return undefined
        let comp = fieldRegistry[fieldConfig.comp].comp;
        return context.vue.$createElement(comp, {
            key: fieldConfig.id,
            props: {
                value: context.formModel[fieldConfig.fieldName],
                title: fieldConfig.fieldTitleName && context.formModel[fieldConfig.fieldTitleName],
            },
            on: {
                'update:value': v => {
                    console.log(v, context.formModel);
                    context.formModel[fieldConfig.fieldName] = v
                },
                'update:title': v => context.formModel[fieldConfig.fieldTitleName] = v
            }
        });
    },
};